package com.yanchangapp.ui.activity._n_manage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.yanchangapp.R;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.ui.presenter.AddFinishAtPresenter;
import com.yanchangapp.ui.view.AddFinishAtView;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.util.ui.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * page: 补写心得....
 */
public class AddFinishActivity extends BaseActivity<AddFinishAtView, AddFinishAtPresenter> implements AddFinishAtView {

    @BindView(R.id.ivToolbarNavigation)
    ImageView ivToolbarNavigation;
    @BindView(R.id.vToolbarDivision)
    View vToolbarDivision;
    @BindView(R.id.tvToolbarTitle)
    TextView tvToolbarTitle;
    @BindView(R.id.etKeyInput)
    EditText etKeyInput;
    @BindView(R.id.btnEnsure)
    Button btnEnsure;

    private long planID;
    private static final String PLAN_ID = "PLAN_ID";


    public static void show(Activity activity,long id){
        Intent intent = new Intent(activity,AddFinishActivity.class);
        intent.putExtra(PLAN_ID,id);
        activity.startActivityForResult(intent, AppConstant.RECODE_FROM_ADD_FINISH);
    }

    @Override
    protected void init() {
        planID = getIntent().getLongExtra(PLAN_ID,-1);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_add_finish;
    }

    @Override
    protected AddFinishAtPresenter createPresenter() {
        return new AddFinishAtPresenter(this);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tvToolbarTitle.setText("补写心得");
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        ivToolbarNavigation.setOnClickListener(v -> finish());

        btnEnsure.setOnClickListener(v -> {
            String msg =  etKeyInput.getText().toString();
            if (TextUtils.isEmpty(msg)){
                UIUtils.showToast("补写心得必填");
            }else {
                mPresenter.putAddFinishPlan(planID,msg);
            }
        });
    }

    @Override
    public void addFinishSuccess(String result) {
        Intent intent = new Intent();
        intent.putExtra("data",result);
        setResult(RESULT_OK,intent);
        finish();
    }

    @Override
    public void addFinishFailure(String err) {
        UIUtils.showToast(err);
    }
}
